#ifndef SERVER_HH_
# define SERVER_HH_

// BSD server style

#include <string>

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

#include "constants/network.h"
//#include "constants/NetworkDevice.hh"


/** Server.cc is only compile on running make 'server' rule
 **
 */

// int getaddrinfo(const char *node, const char *service,
// 		const struct addrinfo *hints,
// 		struct addrinfo **res);
class Server// : public NetworkDevice
{
public:
  /** Ctor
   ** \param port: on which port does the server listen
   */
  Server(char* port);

  /** closes resources (sockets)
   **
   */
  ~Server();

  void setPort(char* port);

  void run();


private:
  /** prints \param msg to stderr if DEBUG is defined
   ** append error msg to log file
   */
  // void displayError(std::string msg);

//#ifdef DEBUG
  void printHints();
//#endif

  void init(char* portString);

  void buildHints();


  // _socket
  struct addrinfo _hints;
  char* _port; // shd be an int

  struct addrinfo *_result, *_rp;
  int _sfd, _s;
  struct sockaddr_storage _peerAddr;
  socklen_t _peerAddrLen;
  ssize_t _nread;
  char _buf[SERVER_BUF_SIZE];
};

#endif /* !SERVER_HH_ */
